package mvp;

import android.app.Activity;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;


import mvp.annotation.PresenterMvpFactoryImpl;

/**
 * @author:ike
 * @function: mvp模式Activity的基类
 * @creat time:14:49 2017/12/14
 **/

public abstract class BaseMvpActivity<V extends IBaseView, P extends BasePresenter<V>, B extends ViewDataBinding> extends AppCompatActivity implements IBaseView {
    protected P presenter;
    protected B bind;
    

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        bind = DataBindingUtil.setContentView(this, initLayout());
        presenter = (P) PresenterMvpFactoryImpl.createPresenterFactory(getClass()).createPresenter();
        presenter.attachView((V) this);
        initListener();
        initData();

        
    }

    public abstract int initLayout();

    public abstract void initListener();

    public abstract void initData();

    @Override
    protected void onDestroy() {
        presenter.deAttachView();
        super.onDestroy();
    }

}
